<?php
namespace app\service;
use think\facade\Db;
use app\model\PaymentModel;
use Exception;

class PaymentService{  

    
    public function list($params){
        
        $data = PaymentModel::alias('a')->field('a.*,b.bank_name as subject')
            ->join('bank b','a.subject_id=b.id','left')
            ->where(['type'=>$params['type'],'outlay_id'=>$params['outlay_id']])->order('id','desc')->select(); 
        return $data;
    }   

    public function save($params){    
        if(empty($params['id'])){           
            $data = PaymentModel::create($params); 
        }else{            
            $data = PaymentModel::update($params, ['id' => $params['id']]); 
        }        
        return $data;
    }

    public function delete($params){   
        $data = PaymentModel::destroy($params['id']);         
        return $data;
    }
}